package com.kvn.cucumber;

import cucumber.api.java.en.And;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import org.junit.Assert;

import java.math.BigDecimal;

/**
 * @author wzy on 2017/8/4.
 */
public class WithdrawStepdefs {
    Account account = new Account();

    @Given("^我的账户中有余额\"([^\"]*)\"元$")
    public void 我的账户中有余额元(String arg0) throws Throwable {
        account.setAmt(new BigDecimal(arg0));
    }

    @When("^我选择固定金额取款方式取出\"([^\"]*)\"元$")
    public void 我选择固定金额取款方式取出元(String arg0) throws Throwable {
       account.withdraw(new BigDecimal(arg0));
       account.setChangeAmt(new BigDecimal(arg0));
    }

    @Then("^我应该收到现金\"([^\"]*)\"元$")
    public void 我应该收到现金元(String arg0) throws Throwable {
        Assert.assertEquals(new BigDecimal(arg0), account.getChangeAmt());
    }

    @And("^我账户的余额应该是\"([^\"]*)\"元$")
    public void 我账户的余额应该是元(String arg0) throws Throwable {
        Assert.assertEquals(new BigDecimal(arg0), account.getAmt());
    }

    class Account {
        private BigDecimal amt;

        private BigDecimal changeAmt;

        public void withdraw(BigDecimal amt){
            this.amt = this.amt.subtract(amt);
        }

        public BigDecimal getAmt() {
            return amt;
        }

        public void setAmt(BigDecimal amt) {
            this.amt = amt;
        }

        public BigDecimal getChangeAmt() {
            return changeAmt;
        }

        public void setChangeAmt(BigDecimal changeAmt) {
            this.changeAmt = changeAmt;
        }



    }
}
